import Vue from 'vue'
import App from './App'
import router from './router'
// import VueAwesomeSwiper from 'vue-awesome-swiper'

// import 'swiper/dist/css/swiper.css'

Vue.config.productionTip = false

import wcSwiper from 'wc-swiper'
import 'wc-swiper/style.css'
Vue.use(wcSwiper);

// 自定义小伙伴定位
import latlng from '@/components/common/latlng'
Vue.component('lat-lng',latlng)

// 修改title
import VueWechatTitle from 'vue-wechat-title';  
Vue.use(VueWechatTitle)

// 日期选择器
// import Calendar from 'vue2-datepick';
// Vue.use(Calendar)

// 省市
// import AmazeVue from 'amaze-vue';
// Vue.use(AmazeVue);

// 滚动条
// import { HappyScroll } from 'vue-happy-scroll'
// Vue.component('happy-scroll', HappyScroll)
// import 'vue-happy-scroll/docs/happy-scroll.css'


// Vue.use(VueAwesomeSwiper)
// import axios from 'axios'
// Vue.use(axios);
// import {post,fetch,patch,put} from './utils/http'
// //定义全局变量
// Vue.prototype.$post=post;
// Vue.prototype.$fetch=fetch;
// Vue.prototype.$patch=patch;
// Vue.prototype.$put=put;
/* eslint-disable no-new */

import './assets/iconfont/iconfont.css'
import axios from 'axios'
import global from './utils/global'
import store from './utils/store'
import wx from 'weixin-js-sdk'
new Vue({
  el: '#app',
  router,
  components: { App },
  template: '<App/>',
   methods:{
   	  // 获取uuid
    getUrlStr(name){
      let reg = new RegExp("(^|\\?|&)" + name + "=([^&]*)(\\s|&|$)","i");
      this.window = window.location.href;
      if(reg.test(window.location.href)){
        return unescape(RegExp.$2.replace(/\+/g," "))
      }
      return undefined
    },
    refrshUuid(){
  
       localStorage.setItem('carWashUuid',0);
       this.choose();
   
    },
         
   
    choose () {

    	var url = window.location.href;
        var pathUrl = Base64.encode(url);

        if (this.getUrlStr('uuid') != undefined) {
          // alert("有参数，前");
          localStorage.setItem('carWashUuid', that.getUrlStr('uuid'));
          localStorage.getItem('carWashUuid');
        }

        if (localStorage.getItem('carWashUuid') != 0) {
        	
          // alert("有缓存，前");
          if (this.getUrlStr('uuid') != undefined) {
            // alert("有缓存，并且有参数");
            var toUrl = url.split('?')[0];
            // window.location.href = toUrl;
            window.location.href = '/#/login';
          }

        } else {
       
          window.location.href = "/app/index.php?i=2&c=entryApi&do=user&m=yimi_car&op=weqingLogin&url=" + pathUrl;
          setTimeout(()=>{
            this.choose();
          },1000)

        }
    },

    // 分享
    getUserUid(){
        
        var that = this;
        axios.get(global.api.index.userUid,{
            params: {
                uuid: localStorage.getItem('carWashUuid')
            }
        })

        .then(function(res){
            
            console.log(res);
            return res.data
        })

        .catch(function(res){
            console.log(res);
        })

    },
    share(){
        var that = this;

        var pathUrl = window.location.href;
        pathUrl = Base64.encode(pathUrl);
        axios.get(global.api.user.jssdk,{
            params: {
                uuid: localStorage.getItem('carWashUuid'),
                url: pathUrl,
            }
        })
        .then(function(res){
        
            console.log("=============share==============");
           
            wx.config({
                debug: false,
                appId: res.data.content.appId,
                timestamp: res.data.content.timestamp,
                nonceStr: res.data.content.nonceStr,
                signature: res.data.content.signature,
                jsApiList: ['updateAppMessageShareData','updateTimelineShareData','onMenuShareTimeline','onMenuShareAppMessage']
            });

            wx.ready(function(res){
                var obj = {  //分享给朋友
                    title: 'e歌上门洗车',
                    desc: '欢迎关注e歌无水洗车！e歌无水洗车,您身边的洗车专家！',
                    link: global.api.baseurl,
                    imgUrl: global.api.baseurl+'assets/img/timg.jpg',
                    success: function () {

                
                        console.log("分享给朋友成功！");
                    },
                    fail: function () {
                       
                        console.log("分享给朋友失败！");
                    }
                }
                var objAll = {  //分享到朋友圈
                    title: 'e歌上门洗车',
                    link: global.api.baseurl,
                    imgUrl: global.api.baseurl+'assets/img/timg.jpg',
                    success: function () {
                        console.log("分享到朋友圈成功！");
                    },
                    fail: function () {
                        console.log("分享到朋友圈失败！");
                    }
                }
                wx.onMenuShareAppMessage(obj);  //分享给朋友
                wx.onMenuShareTimeline(objAll);  //分享到朋友圈
            });
            wx.error(function(res){
                console.log(res);
            })
        })
        .catch(function(res){
            console.log(res);
        })
    },
    washShare(){
        var that = this;
        var pathUrl = window.location.href;
        pathUrl = Base64.encode(pathUrl);
        axios.get(global.api.user.jssdk,{
            params: {
                uuid: localStorage.getItem('carWashUuid'),
                url: pathUrl,
            }
        })
        .then(function(res){
            // console.log("=============share==============");
            console.log(res);
            wx.config({
                debug: false,
                appId: res.data.content.appId,
                timestamp: res.data.content.timestamp,
                nonceStr: res.data.content.nonceStr,
                signature: res.data.content.signature,
                jsApiList: ['updateAppMessageShareData','updateTimelineShareData','onMenuShareTimeline','onMenuShareAppMessage']
            });
            wx.ready(function(res){
                var obj = {  //分享给朋友
                    title: 'e歌上门洗车',
                    desc: '欢迎关注e歌无水洗车！e歌无水洗车,您身边的洗车专家！',
                    link: '/#/',
                    imgUrl: '/assets/img/timg.jpg',
                    success: function () {
                        console.log("分享给朋友成功！");
                    },
                    fail: function () {
                        console.log("分享给朋友失败！");
                    }
                }
                var objAll = {  //分享到朋友圈
                    title: 'e歌上门洗车',
                    link: '/#/',
                    imgUrl: '/assets/img/timg.jpg',
                    success: function () {
                        console.log("分享到朋友圈成功！");
                    },
                    fail: function () {
                        console.log("分享到朋友圈失败！");
                    }
                }
                wx.onMenuShareAppMessage(obj);  //分享给朋友
                wx.onMenuShareTimeline(objAll);  //分享到朋友圈
            });
            wx.error(function(res){
                console.log(res);
            })
        })
        .catch(function(res){
            console.log(res);
        })
    },

}
})
